package Easy;

public class Solution58 {
    public int lengthOfLastWord(String s) {
        if (s.length() == 0)
            return 0;
        int pre = 0, post = 0;
        int preLen = 0;
        for (; post < s.length(); post++) {
            if (s.charAt(post) == ' ')
                break;
        }
        if (post == s.length())
            return post;
        else {
            preLen = post++;
        }

        while (post < s.length()) {
            if (s.charAt(post) == ' ') {
                post++;
                continue;
            }
            if (pre != post - preLen)
                pre = post;
            post++;
            preLen=post-pre;

        }
        return preLen;
    }

    public static void main(String[] args) {
        Solution58 s58 = new Solution58();
        System.out.println(s58.lengthOfLastWord("    "));
    }
}
